/*
ID: simplyz2
LANG: C
TASK: ride
 */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_LEN 7
#define MOD 47
char comet[MAX_LEN], group[MAX_LEN];

void
solve()
{
	int rt1, rt2, i, len, tmp;
	len = strlen(comet);
	tmp = comet[0]-'A'+1;
	for(i=1; i<len; i++)
		tmp *= (comet[i]-'A'+1);
	rt1 = tmp % MOD;
	len = strlen(group);
	tmp = group[0]-'A'+1;
	for(i=1; i<len; i++)
		tmp *= (group[i]-'A'+1);
	rt2 = tmp % MOD;
	printf("%s\n", rt1==rt2 ? "GO" : "STAY");
}

int
main(int argc, char **argv)
{
	freopen("ride.in", "r", stdin);
	freopen("ride.out", "w", stdout);
	while(scanf("%s %s", comet, group) != EOF) {
		solve();
	}
	exit(0);
}
